﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DataAdapter对象 : System.Web.UI.Page
{
    protected string sql;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            DataAddapterObject();//調用DataAdapter对象,填充DataSet
          
        }


    }

    private void DataAddapterObject()//订意构造HAN数
    {
        SqlConnection MyConn = new SqlConnection(ConfigurationManager.AppSettings["SqlConn"]);
        sql = "select * from zhuanti ";
        SqlDataAdapter MyDa = new SqlDataAdapter(sql, MyConn);//DataAdapter和Command一样用的
        MyDa.SelectCommand.CommandType = CommandType.Text;//定义SelectCommand的执行类型
        try
        {
            MyConn.Open();//打开
            DataSet dataset = new DataSet();//订义DataSet对象
            MyDa.Fill(dataset);//便用fill()方法填充DataSet数据
            MyConn.Close();
            myDataGrid.DataSource = dataset;//设置dataGrid控件的数据源,并绑定数据
            myDataGrid.DataBind();
        }
        catch (Exception xx)
        {
          Response.Write(xx.Message);
        }
        }


    protected void dd(object source, DataGridPageChangedEventArgs e)
    {
        myDataGrid.CurrentPageIndex = e.NewPageIndex;

        myDataGrid.DataBind();
    }
}
